$(document).ready(function(){
    var region_1 = $("#region_1");
    var region_2 = $("#region_2");
    var region_3 = $("#region_3");
    region_1.change(function(){
        $params = JSON.stringify({'region_id':$(this).val()});
        $second_region_back = ajaxSynchroRequest("/user/info/get-sub-region",$params);
        console.log($second_region_back);
        var options = '<option value="0">--请选择--</option>';
        $.each($second_region_back.data,function(index,value){
            options += '<option value="'+value.id+'">'+value.name+'</option>';
       });
       region_2.empty(); 
       region_2.append(options);
       region_3.empty();
       region_3.append('<option value="0">--请选择--</option>');
    });
    region_2.change(function(){
        $params = JSON.stringify({'region_id':$(this).val()});
        $third_region_back = ajaxSynchroRequest("/user/info/get-sub-region",$params);
        console.log($third_region_back);
        var options = '<option value="0">--请选择--</option>';
        $.each($third_region_back.data,function(index,value){
            options += '<option value="'+value.id+'">'+value.name+'</option>';
       });
       region_3.empty();
       region_3.append(options);
    });
    $("#region-submit").on('click',function(){
        if(region_1.val()==0 || region_2.val()==0 || region_3.val()==0){
            layer.msg('请选择地区！');
            return false;
        }
        else{
            $("#region-set-form").submit();
        }
    })
});
